package com.youxuit.youxu.kecheng.SynchronizedDemo;

/**
 * 类锁
 * syncchronized加在static方法上
 */
public class SyncronizedClassStatic4 implements Runnable{

    public static SyncronizedClassStatic4 block1 = new SyncronizedClassStatic4();
    public static SyncronizedClassStatic4 block2 = new SyncronizedClassStatic4();


    @Override
    public void run() {
        methord();
    }

    private static synchronized void methord() {
        System.out.println("我的线程名字是：" + Thread.currentThread().getName() + ",我开始运行了");

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {

        }
        System.out.println("我的线程名字是：" + Thread.currentThread().getName() + "，运行结束了");
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(block1, "t1");
        Thread t2 = new Thread(block2, "t2");
        t1.start();
        t2.start();

        while (t1.isAlive() || t2.isAlive()) {

        }
        System.out.println("finish");
    }
}
